/**
 * 
 */
package com.dingding.order.core.orderlist.biz.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.AbstractResponse;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.order.core.orderlist.biz.IGetNearbyOrderListService;
import com.dingding.order.core.orderlist.dao.ITaxiGetNearbyOrderListDao;
import com.dingding.order.dto.orderlist.ReqTaxiGetNearbyOrderListDTO;
import com.dingding.order.dto.orderlist.ResTaxiGetNearbyOrderList;
import com.dingding.order.dto.orderlist.TaxiNearbyOrder;

/**
 * @ClassName: TaxiGetNearbyOrderListServiceImpl
 * @Description:出租车获取附近订单列表
 * @author zhouxuan
 * @date 2016年6月30日 上午11:48:16
 * @since V2.3.0
 */
@Component("taxiGetNearbyOrderListService")
public class TaxiGetNearbyOrderListServiceImpl
		extends AbstractResponse<ResTaxiGetNearbyOrderList, ReqTaxiGetNearbyOrderListDTO>
		implements IGetNearbyOrderListService {

	@Resource(name = "taxiGetNearbyOrderListDao")
	ITaxiGetNearbyOrderListDao taxiGetNearbyOrderListDao;

	/**
	 * @Title: getNearOrderList
	 * @Description:出租车获取附近订单列表
	 * @author zhouxuan
	 * @return String 转换成JSON的响应bean
	 * @since V2.3.0
	 */
	@Override
	public String getNearOrderList(String requestData) {
		// 将对象转换为请求bean
		ReqTaxiGetNearbyOrderListDTO reqTaxiGetNearbyOrderListDTO = super.parseRequestJson(requestData);
		ResponseEntity<ResTaxiGetNearbyOrderList> response = new ResponseEntity<ResTaxiGetNearbyOrderList>();
		// 1.验证请求参数
		if (!validateParam(response, reqTaxiGetNearbyOrderListDTO)) {
			return super.responseBeanToJson(response);
		}
		// 2.获取附近订单列表
		List<TaxiNearbyOrder> taxiNearbyOrderlists = getNearbyOrderLists(reqTaxiGetNearbyOrderListDTO);
		// 3.拼装响应
		assemblyContent(response, taxiNearbyOrderlists);
		return super.responseBeanToJson(response);
	}

	/**
	 * @Title: assemblyContent
	 * @Description:拼装响应bean
	 * @author zhouxuan
	 * @return ResTaxiGetNearbyOrderList 出租车附近订单列表的响应bean
	 * @since V2.3.0
	 */
	private ResTaxiGetNearbyOrderList assemblyContent(ResponseEntity<ResTaxiGetNearbyOrderList> response,
			List<TaxiNearbyOrder> taxiNearbyOrderlists) {
		ResTaxiGetNearbyOrderList resTaxiGetNearbyOrderList = new ResTaxiGetNearbyOrderList();
		resTaxiGetNearbyOrderList.setTaxiNearbyOrderLists(taxiNearbyOrderlists);

		response.setCode(HttpStatus.SC_OK);
		response.setResponseBody(resTaxiGetNearbyOrderList);
		return resTaxiGetNearbyOrderList;
	}

	/**
	 * 
	 * @Title: getNearbyOrderLists
	 * @Description:出租车获取附近订单列表
	 * @author zhouxuan
	 * @return List<TaxiNearbyOrder> 排序后的出租车附近订单列表
	 * @since V2.3.0
	 */
	private List<TaxiNearbyOrder> getNearbyOrderLists(ReqTaxiGetNearbyOrderListDTO reqTaxiGetNearbyOrderListDTO) {
		return this.taxiGetNearbyOrderListDao.taxiGetNearbyOrderList(reqTaxiGetNearbyOrderListDTO);
	}
}
